<template>
	<view class="news">
		
		<!-- 新闻信息 -->
		<view class="todayNews">
			<!-- 标题 -->
			<view class="commonTitle">--新闻信息--</view>
			<!-- 新闻列表 -->
			<view class="newsList">
				<view class="newItem" v-for="(item) in newsList" :key="item.id" @click="toDetail(item.sourceUrl)">
					<view class="newsTitle">{{item.title}}</view>
					<view class="newsInfo">
						<text>{{item.infoSource}}</text>
						<text>{{item.pubDateStr}}</text>
						<!-- <text>{{item.riskarea.mid}}</text> -->
		
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsList: [],
			}
		},
		methods: {
			// 1.获取新闻数据的方法
			getTodayNewsData() {
				uni.request({
					url: "https://api.tianapi.com/txapi/ncov/index?key=83fcdb1b0eaf62904f7869267cea8b97",
					method: "GET",
					success: (res) => {
						if (res.data.code == 200) {
							this.newsList = res.data.newslist[0].news
						}
					}
			
			
				})
			},
			// 2.跳转到新闻详情页方法
			toDetail(sourceURL) {
				// 获取新闻内容详情链接
				// console.log(sourceURL)
				// 跳转到新闻详情页面
				uni.navigateTo({
					url: "../index/detail?url=" + sourceURL
				})
			},
		},
		onLoad() {
			this.getTodayNewsData()
		}
	}
</script>

<style lang="scss">
.news{
	// 今日动态样式
	.todayNews {
		.newsList {
			.newItem {
				padding: 20rpx 10rpx;
				border-bottom: 1px solid #eee;
	
				.newsTitle {
					font-size: 38rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
				}
	
				.newsInfo {
					display: flex;
					justify-content: space-between;
					color: #999;
					font-size: 35rpx;
				}
			}
		}
	
		// 公共标题
		.commonTitle {
			height: 120rpx;
			line-height: 120rpx;
			text-align: center;
			font-weight: bold;
			font-size: 40rpx;
		}
	
	}
}
</style>
